package com.jjwxc.jwjskandriod.activity

import android.content.ClipData
import android.content.ClipboardManager
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.widget.AppCompatButton
import com.jjwxc.jwjskandriod.R
import com.jjwxc.jwjskandriod.framework.http.FFNetWork

class RequestLogger : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_request_logger)

        val root = findViewById<LinearLayout>(R.id.ll_container)
        val logs = FFNetWork.curlLogs
        var odd = false
        logs.forEach { text ->
            val tv = TextView(this)
            tv.text = text
            tv.setPadding(20, 30, 20, 30)
            if (odd) {
                tv.setTextColor(resources.getColor(R.color.color_main))
            } else {
                tv.setTextColor(resources.getColor(R.color.blue_text))
            }
            odd = !odd
            tv.setOnLongClickListener { v ->
                val clipboard: ClipboardManager =
                    getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
                val clip = ClipData.newPlainText("label", text)
                clipboard.setPrimaryClip(clip)
                Toast.makeText(this, "已复制到剪切板", Toast.LENGTH_SHORT).show()
                true
            }

            root.addView(tv)
        }

        findViewById<AppCompatButton>(R.id.btn_clear).setOnClickListener { v ->
            FFNetWork.curlLogs.clear()
            finish()
        }
    }
}